**** Replication file ****
***The Politics of Alliance Cohesion: Experimental Evidence on American Attitudes toward Corrective Measures in Security Partnerships
***to be published at Perspectives on Politics***
*Osman Sabri Kiratli osmansabrikiratli@gmail.com


preserve
keep if Q14_1_3==6

*figure1(left-panel)
reg Q3 i.actionn1x ib5.corrective countryn1x countryn2x countryn3x, cluster ( ResponseId)
margins ib5.corrective, post
coefplot, xscale(range(4 7)) xlabel(4(1)7)

*figure1(right-panel)
reg Q3 i.corrective i.countryn1x i.countryn2x i.countryn3x if actionn1x==1, cluster ( ResponseId)
margins corrective    ,  post
estimates store A
reg Q3 i.corrective i.countryn1x i.countryn2x i.countryn3x if actionn1x==2, cluster ( ResponseId)
margins corrective    ,  post
estimates store B
reg Q3 i.corrective i.countryn1x i.countryn2x i.countryn3x if actionn1x==3, cluster ( ResponseId)
margins corrective    ,  post
estimates store C
reg Q3 i.corrective i.countryn1x i.countryn2x i.countryn3x if actionn1x==4, cluster ( ResponseId)
margins corrective    ,  post
estimates store D
reg Q3 i.corrective i.countryn1x i.countryn2x i.countryn3x if actionn1x==5, cluster ( ResponseId)
margins corrective    ,  post
estimates store E
coefplot (A, label(Veto)) (B, label(Break sanctions)) (C, label(Rival weapons)) (D, label(Underspending)) (E, label(No troops))  

*figure2(left-panel)
reg sQ5 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective, cluster ( ResponseId)
coefplot, xline(0)  drop(*.corrective _cons) keep(*:) omitted baselevels caption("Support for American contributions", position(6) justification(center))
*figure2(right-panel)
reg Q4 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective, cluster ( ResponseId)
coefplot, xline(0)  drop(*.corrective _cons) keep(*:) omitted baselevels caption("Alliance favorability", position(6)justification(center))



*Figure-3(left-panel)
reg Q3 c.countryn1x##ib5.corrective   i.countryn2x i.countryn3x,robust  cluster ( ResponseId)
margins, dydx(countryn1x) over (corrective) post
coefplot , xline(0) caption("Average marginal effects of Regime", position(6) justification(center))

*Figure-3(middle-panel)
reg Q3 c.countryn2x##ib5.corrective i.countryn1x  i.countryn3x,robust  cluster ( ResponseId)
margins, dydx(countryn2x) over (corrective) post 
coefplot, xline(0) xscale(range(-0.4 0.4)) xlabel(-0.4(0.2)0.4) caption("Average marginal effects of Military", position(6) justification(center))

*Figure-3(right-panel)
reg Q3 c.countryn3x##ib5.corrective i.countryn1x i.countryn2x ,robust  cluster ( ResponseId)
margins, dydx(countryn3x) over (corrective) post 
coefplot, xline(0) caption("Average marginal effects of Treaty", position(6) justification(center))


***Appendix***

*a-2a balance tables
tabulate actionn1x, generate(actionn1x_)
tabulate countryn1x, generate(countryn1x_)
tabulate countryn2x, generate(countryn2x_)
tabulate countryn3x, generate(countryn3x_)
estpost tabstat actionn1x_* countryn1x_* countryn2x_* countryn3x_*,   by(corrective) statistics(mean) columns(statistics)
esttab using "balance_table.rtf", replace     cells("mean(fmt(3))")     title("Balance Table: Treatment Proportions by Primary Treatment (corrective)")     mtitles("Level 1" "Level 2" "Level 3" "Level 4" "Level 5")    addnotes("Note: Table shows proportion of observations in each treatment category within each corrective group. Values should be approximately equal across columns if randomization worked.")

foreach var of varlist actionn1x countryn1x countryn2x countryn3x {
    quietly tab `var' corrective, chi2
    local chi2_val = string(r(chi2), "%6.3f")
    local p_val = string(r(p), "%6.3f") 
    local balanced = cond(r(p) > 0.05, "Yes", "No")
    display "`var'" _col(16) "`chi2_val'" _col(25) "`p_val'" _col(35) "`balanced'"
}

*a-2b power analysis
power twomeans 5.85 5.35, n1(500) n2(500) sd(2.5) alpha(0.05)
power twomeans 5.85 5.35, n1(750) n2(750) sd(2.5) alpha(0.05)


*tablea3
*M1
reg Q3 i.actionn1x ib5.corrective i.countryn1x i.countryn2x i.countryn3x , cluster ( ResponseId)
est sto r1
*M2
reg Q3 i.actionn1x##ib5.corrective i.countryn1x i.countryn2x i.countryn3x , cluster ( ResponseId)
est sto r2
*M3
reg Q3 i.actionn1x ib5.corrective Q2_2 edu Q16_1__1  Q16_4 i.countryn1x i.countryn2x i.countryn3x , cluster ( ResponseId)
est sto r3
*M4
reg Q3 i.actionn1x##ib5.corrective Q2_2 edu Q16_1__1  Q16_4 i.countryn1x i.countryn2x i.countryn3x , cluster ( ResponseId)
est sto r4
/*Generate user-friendly version of Table 1*/
esttab r1 r2 r3 r4, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label compress nogaps mtitles 

*tablea4
*M1
reg sQ5 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective, cluster ( ResponseId)
est sto r1
*M2
reg Q4 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective, cluster ( ResponseId)
est sto r2
*M3
reg sQ5 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective Q2_2 edu Q16_1__1  Q16_4, cluster ( ResponseId)
est sto r3
*M4
reg Q4 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective Q2_2 edu Q16_1__1  Q16_4, cluster ( ResponseId)
est sto r4
esttab r1 r2 r3 r4, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label compress nogaps mtitles

*tablea5
*M1
reg Q3 c.countryn1x##ib5.corrective i.actionn1x i.countryn2x i.countryn3x,robust  cluster ( ResponseId)
est sto r1
*M2
reg Q3 c.countryn2x##ib5.corrective i.actionn1x i.countryn1x i.countryn3x ,robust  cluster ( ResponseId)
est sto r2
*M3
reg Q3 c.countryn3x##ib5.corrective i.actionn1x i.countryn2x i.countryn1x,robust  cluster ( ResponseId)
est sto r3
*M4
reg Q3 c.countryn1x##ib5.corrective Q2_2 edu Q16_1__1  Q16_4,robust  cluster ( ResponseId)
est sto r4
*M5
reg Q3 c.countryn2x##ib5.corrective Q2_2 edu Q16_1__1  Q16_4,robust  cluster ( ResponseId)
est sto r5
*M6
reg Q3 c.countryn3x##ib5.corrective Q2_2 edu Q16_1__1  Q16_4,robust  cluster ( ResponseId)
est sto r6
esttab r1 r2 r3 r4 r5 r6, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label  compress nogaps mtitles

*Figure-A-2
reg  Q3 i.countryn1x i.actionn1x i.countryn2x i.countryn3x  if corrective==1, cluster ( ResponseId)
margins countryn1x    ,  post
estimates store A
reg  Q3 i.countryn1x i.actionn1x i.countryn2x i.countryn3x  if corrective==2, cluster ( ResponseId)
margins countryn1x    ,  post
estimates store B
reg  Q3 i.countryn1x i.actionn1x i.countryn2x i.countryn3x  if corrective==3, cluster ( ResponseId)
margins countryn1x    ,  post
estimates store C
reg  Q3 i.countryn1x i.actionn1x i.countryn2x i.countryn3x   if corrective==4, cluster ( ResponseId)
margins countryn1x    ,  post
estimates store D
reg  Q3 i.countryn1x i.actionn1x i.countryn2x i.countryn3x  if corrective==5, cluster ( ResponseId)
margins countryn1x    ,  post
estimates store E
coefplot (A, label(Break alliance)) (B, label(Economic measures)) (C, label(Denounce)) (D, label(Reduce military support)) (E, label(No change))  

*Figure-a-3
*left-panel
reg Q3 c.partisan##ib5.corrective i.actionn1x i.countryn1x i.countryn2x i.countryn3x,robust  cluster ( ResponseId)
margins ,dydx( partisan ) over (corrective) post
coefplot, xline(0)
*right-panel
reg Q3 c.ideo##ib5.corrective i.actionn1x i.countryn1x i.countryn2x i.countryn3x,robust  cluster ( ResponseId)
margins ,dydx( ideo ) over (corrective) post
coefplot, xline(0)
gr combine Graphparti.gph Graphideo.gph, xcommon ycommon row(1)

*tablea6
reg Q3 c.partisan##ib5.corrective i.actionn1x i.countryn1x i.countryn2x  i.countryn3x  ,robust  cluster ( ResponseId)
est sto r1
reg Q3 c.ideo##ib5.corrective i.actionn1x i.countryn1x i.countryn2x  i.countryn3x ,robust  cluster ( ResponseId)
est sto r2
reg Q3 c.partisan##ib5.corrective Q2_2 edu Q16_1__1  Q16_4 i.actionn1x i.countryn1x i.countryn2x  i.countryn3x ,robust  cluster ( ResponseId)
est sto r3
reg Q3 c.ideo##ib5.corrective Q2_2 edu Q16_1__1  Q16_4 i.actionn1x i.countryn1x i.countryn2x  i.countryn3x ,robust  cluster ( ResponseId)
est sto r4
esttab r1 r2 r3 r4, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label compress nogaps mtitles 

restore 

*tablea7
*M1
reg Q3 i.actionn1x ib5.corrective, cluster ( ResponseId)
est sto r1
*M2
reg Q3 i.actionn1x##ib5.corrective , cluster ( ResponseId)
est sto r2
esttab r1 r2, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label compress nogaps mtitles 

*tablea8
*M1
reg sQ5 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective, cluster ( ResponseId)
est sto r1
*M2
reg Q4 i.actionn1x i.countryn1x i.countryn2x i.countryn3x i.corrective, cluster ( ResponseId)
est sto r2

esttab r1 r2, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label compress nogaps mtitles

*tablea9
*M1
reg Q3 c.countryn1x##ib5.corrective ,robust  cluster ( ResponseId)
est sto r1
*M2
reg Q3 c.countryn2x##ib5.corrective   ,robust  cluster ( ResponseId)
est sto r2
*M3
reg Q3 c.countryn3x##ib5.corrective  ,robust  cluster ( ResponseId)
est sto r3
esttab r1 r2 r3, b(2) se(2) star(* 0.05 ** 0.01 *** 0.001) label compress nogaps mtitles


